package com.example.zlm.ndk;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import java.security.spec.InvalidKeySpecException;
import java.util.Date;

public class MainActivity extends AppCompatActivity {
    EditText inputNumber;
    TextView text_show;
    TextView text_showDe;
    DESUtils desUtils;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        desUtils=new DESUtils();
        try {
            desUtils.init();
        } catch (InvalidKeySpecException e) {
            e.printStackTrace();
        }
        inputNumber=(EditText) findViewById(R.id.EnCode_number);
        Button but= (Button)findViewById(R.id.But_GetEncode);
        Button butDe= (Button)findViewById(R.id.But_GetDecode);
         text_show=(TextView) findViewById(R.id.text_show);
        text_showDe=(TextView) findViewById(R.id.text_showDe);
        but.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //NDKUtils.getAesEnCodeString(inputNumber.getText().toString());
                //text_show.setText(NDKUtils.encode(inputNumber.getText().toString()));

                text_show.setText(desUtils.DESEncode(inputNumber.getText().toString()));
            }
        });

        butDe.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               // text_showDe.setText(NDKUtils.decode(text_show.getText().toString()));

                text_showDe.setText(desUtils.DESDecode(text_show.getText().toString()));
            }
        });
        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, new String("intNumber"+NDKUtils.getIntNumber("")+NDKUtils.getTime("xoxooxo")), Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
